<?php
/***
 * 描述：手机端基类模块
 * @category		
 * @package			Lib		
 * @subpackage	Action.Office
 * @author				wanght <whtaok@gmail.com>
 * @since				2013-7-6
 * @version			$Id: MobileAction.class.php 87 2013-12-08 02:59:26Z whtaok@gmail.com $
 */
define('IS_MOBILE', TRUE);
class MobileAction extends AppAction {	
	/**
	 * 描述：初始化模块
	 * @access		protected
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-4-14
	 */
	protected  function _initialize() {
		$this->checkShop();
	}
	
	public function jumpLastUrlAct(){
		$lastUrl = I('lastUrl');
		if($lastUrl){
			$lastUrl = urldecode(base64_decode(I('lastUrl')));
		}else{
			$lastUrl = C('SITE_WAP').U('Cust/index');
		}
		header('location:'.$lastUrl);
	}
	
	/**
	 * 描述：检查是否登录成功，及操作权限
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-4-14
	 */
	protected function checkAuth() {
		if (!session(SES_CUST_ID)) {
			$lastUrl = I('lastUrl',base64_encode(urlencode("http://".$_SERVER["SERVER_NAME"].$_SERVER['REQUEST_URI'])));
			$this->success('您尚未登录或登录超时，请重新登录。',U('CustPassport/index',array('lastUrl'=>$lastUrl)));
			exit;
		}else{
			$this->curr_cust_id = session(SES_CUST_ID);
		}
	}
	
	protected function checkShop(){
		$shop = cookie(COK_SHOP);
		$shop_id = session(SES_SHOP_ID);
		if($shop){
			if($shop_id){
				//cookie中商铺存在，并且session中商铺ID也存在,直接返回
				$this->curr_shop_id = $shop_id;
			}else{
				//cookie中商铺存在，session中商铺ID不存在，校验商铺信息
				//$shopInfo = split('|', $shop);
				$mod = new ShopLibModel();
				$list = $mod->findOpenedList();
				if(count($list)==1){
					session(SES_SHOP_ID,$list[0]['id']);
					$this->curr_shop_id = $list[0]['id'];
					cookie(COK_SHOP,$list[0]['id'].'|'.$list[0]['district'].'|'.$list[0]['address']);
				}else{
					//跳转至店铺选择页面
					$this->redirect('Index/showChgshop');
				}
			}
		}else{
			$mod = new ShopLibModel();
			$list = $mod->findOpenedList();
			if(count($list)==1){
				//如果只有一个店铺
				$flag = true;
				$this->curr_shop_id = $list[0]['id'];
				session(SES_SHOP_ID,$list[0]['id']);
				cookie(COK_SHOP,$list[0]['id'].'|'.$list[0]['district'].'|'.$list[0]['address']);
			}else{
				//跳转至店铺选择页面
				$flag = false;
				session(SES_SHOP_ID,$list[0]['id']);
				$this->curr_shop_id = $list[0]['id'];
				$this->assign('isShowShop','1');
				$this->assign('tempShopAddress',$list[0]['address']);
				//跳转至店铺选择页面
				$this->redirect('Index/showChgshop');
			}
			
		}
	}
}
	

?>